home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Persist / Adrs_BOM.pas next >
Encoding:
Pascal/Delphi Source File  |  2000-01-19  |  6.5 KB  |  243 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   (c) TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: Jan 2000
  10.  
  11.   Notes: Business object model for the Address book demo
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit Adrs_BOM;
  15.  
  16. interface
  17. uses
  18.   tiPtnVisitor
  19.   ,tiPerObjAbs
  20.   ,Classes
  21.   ;
  22.  
  23. type
  24.  
  25.   // A list of TPerson objects, with some published properties for display in a
  26.   // TtiTreeView
  27.   //----------------------------------------------------------------------------
  28.   TPersonList   = class( TVisList )
  29.   protected
  30.     function GetCaption : string ; override ;
  31.   published
  32.     property Caption ;
  33.     property List ;
  34.   end ;
  35.  
  36.   // A list of TAddress objects
  37.   //----------------------------------------------------------------------------
  38.   TAddressList  = class( TVisList )
  39.   protected
  40.   published
  41.   end;
  42.  
  43.   // A list of TEAddress objects
  44.   //----------------------------------------------------------------------------
  45.   TEAddressList = class( TVisList )
  46.   protected
  47.   published
  48.   end;
  49.  
  50.   // The TAdrsBook class. Top of the tree of the Address Book BOM
  51.   //----------------------------------------------------------------------------
  52.   TAdrsBook = class( TPerObjAbs )
  53.   private
  54.     FPersonList    : TPersonList    ;
  55.   protected
  56.     function GetCaption : string ; override ;
  57.   published
  58.     property People    : TPersonList read FPersonList ;
  59.     property Caption ;
  60.   public
  61.     constructor Create ; override ;
  62.     destructor  Destroy ; override ;
  63.   end ;
  64.  
  65.  
  66.   // TPerson class. Holds information about a person
  67.   //----------------------------------------------------------------------------
  68.   TPerson = class( TPerObjAbs )
  69.   private
  70.     FAddressList  : TAddressList ;
  71.     FEAddressList : TEAddressList ;
  72.     FsFirstname: string;
  73.     FsLastName: string;
  74.     FsInitials : string ;
  75.     FsTitle: string;
  76.     FsNotes: string;
  77.   protected
  78.     function GetCaption : string ; override ;
  79.   published
  80.     property Caption ;
  81.     property EAddressList : TEAddressList read FEAddressList ;
  82.     property AddressList  : TAddressList  read FAddressList ;
  83.   public
  84.     constructor Create ; override ;
  85.     destructor  Destroy ; override ;
  86.     property LastName : string
  87.              read FsLastName
  88.              write FsLastName ;
  89.     property FirstName : string
  90.              read FsFirstname
  91.              write FsFirstName ;
  92.     property Title : string
  93.              read  FsTitle
  94.              write FsTitle ;
  95.     property Initials : string
  96.              read  FsInitials
  97.              write FsInitials ;
  98.     property Notes : string
  99.              read FsNotes
  100.              write FsNotes ;
  101.   end ;
  102.  
  103.  
  104.   // The TAddress class. Holds conventional ( street & postage ) address info
  105.   //----------------------------------------------------------------------------
  106.   TAddress = class( TPerObjAbs )
  107.   private
  108.     FsLines   : string ;
  109.     FsState   : string;
  110.     FsCountry: string;
  111.     FsPCode: string;
  112.     FsAdrsType: string;
  113.     function GetText: string;
  114.   protected
  115.   published
  116.     property AdrsType : string
  117.              read FsAdrsType
  118.              write FsAdrsType ;
  119.     property Text : string read GetText ;
  120.   public
  121.     property Country : string
  122.              read FsCountry
  123.              write FsCountry ;
  124.  
  125.     property Lines : string
  126.              read  FsLines
  127.              write FsLines ;
  128.     property State : string
  129.              read  FsState
  130.              write  FsState ;
  131.     property PCode : string
  132.              read  FsPCode
  133.              write  FsPCode ;
  134.   end ;
  135.  
  136.   // The TEAddress class. Holds info about an EAddress like phone number or EMail
  137.   //----------------------------------------------------------------------------
  138.   TEAddress = class( TPerObjAbs )
  139.   private
  140.     FsText: string;
  141.     FEAdrsType: string;
  142.   protected
  143.     function GetCaption : string ; override;
  144.   published
  145.     property EAdrsType : string
  146.              read FEAdrsType
  147.              write FEAdrsType ;
  148.     property Text : string
  149.              read FsText
  150.              write FsText ;
  151.   public
  152.     property Caption ;
  153.   end ;
  154.  
  155.  
  156. implementation
  157. uses
  158.   tiUtils
  159.   ;
  160.  
  161. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  162. // *
  163. // * TAdrsBook
  164. // *
  165. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  166. constructor TAdrsBook.Create;
  167. begin
  168.   inherited;
  169.   FPersonList := TPersonList.Create ;
  170. end;
  171.  
  172. //------------------------------------------------------------------------------
  173. destructor TAdrsBook.Destroy;
  174. begin
  175.   FPersonList.Free ;
  176.   inherited;
  177. end;
  178.  
  179. //------------------------------------------------------------------------------
  180. function TAdrsBook.GetCaption: string;
  181. begin
  182.   result := 'Address book' ;
  183. end;
  184.  
  185. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  186. // *
  187. // * TPerson
  188. // *
  189. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  190. constructor TPerson.Create;
  191. begin
  192.   inherited;
  193.   FAddressList  := TAddressList.Create ;
  194.   FEAddressList := TEAddressList.Create ;
  195. end;
  196.  
  197. //------------------------------------------------------------------------------
  198. destructor TPerson.Destroy;
  199. begin
  200.   FAddressList.Free ;
  201.   FEAddressList.Free ;
  202.   inherited;
  203. end;
  204.  
  205. //------------------------------------------------------------------------------
  206. function TPerson.GetCaption: string;
  207. begin
  208.   result := LastName + ', ' + FirstName ;
  209. end;
  210.  
  211. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  212. // *
  213. // * TEAddress
  214. // *
  215. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  216. function TEAddress.GetCaption: string;
  217. begin
  218.   result := EAdrsType + ' ' + Text ;
  219. end;
  220.  
  221. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  222. // *
  223. // * TPersonList
  224. // *
  225. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  226. function TPersonList.GetCaption: string;
  227. begin
  228.   result := 'People' ;
  229. end;
  230.  
  231. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  232. // *
  233. // * TAddress
  234. // *
  235. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  236. function TAddress.GetText: string;
  237. begin
  238.   result := tiStrTran( Lines, #13+#10, ', ' ) + ' '
  239.             + State + PCode + Country ;
  240. end ;
  241.  
  242. end.
  243.